#include "ex04-library.h"

// Task 4(a).  Write a placeholder implementation of LimitedBuffer's
//             constructor and methods

// Task 4(b).  Write a working implementation of write() and occupancy()

// Task 4(c).  Write a working implementation of read()

// Do not modify
Buffer::~Buffer()
{
    // Empty destructor
}

LimitedBuffer::LimitedBuffer(int capacity, int value)
    : capacity(capacity), value(value)
{
}
void LimitedBuffer::write(int v)
{
    if (buffer.size() == capacity)
        return;
    buffer.push_back(v);
}
unsigned int LimitedBuffer::occupancy()
{
    return capacity;
}
int LimitedBuffer::read()
{
    if (buffer.size() == 0)
        return value;
    int v = *(buffer.rbegin());
    buffer.pop_back();
    return v;
}
